package com.zmm.util.component;

import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.URLUtil;
import com.zmm.common.log.ReqRspLog;
import com.zmm.util.ip.IpUtil;
import com.zmm.util.time.DateUtil;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;

/**
 * @author 900045
 * @description:
 * @name PackingUtil
 * @date By 2021-08-13 14:50:05
 */
public final class PackingUtil {

	public static void packingReqRspLog(HttpServletRequest request, Object result, Method method, Object[] args, ReqRspLog webLog){
		String urlStr = request.getRequestURL().toString();
		webLog.setBasePath(StrUtil.removeSuffix(urlStr, URLUtil.url(urlStr).getPath()));
		webLog.setIp(IpUtil.getIpAddress(request));
		webLog.setMethod(request.getMethod());
		webLog.setParameter(ParameterUtil.getParameter(method, args));
		webLog.setResult(result);
		webLog.setUri(request.getRequestURI());
		webLog.setUrl(request.getRequestURL().toString());
	}
}
